<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\AdminRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

class HomeController extends Controller
{
    //

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware(['auth.admin']);
    }

    //后台首页
    function   index(){

        return  view('admin.home.home');
    }

    //后台欢迎页
    function  welcome(){

        return view('admin.home.welcome');
    }

    //基本资料
    public function person()
    {

        return view('admin.home.person');
    }

    //更改密码
    public function doChangePassword(AdminRequest $request)
    {
        //检查旧密码是否正确
        $admin = auth('admin')->user();
        //dd($admin);
        if(!Hash::check($request->old_password,$admin->password)){
            return user_business_handler()->fail('输入的旧密码不正确');
        }

        if($request->password != $request->confirm_password){
            return  user_business_handler()->fail('两次输入的密码不一致');
        }
        $admin->password = bcrypt($request->password);
        $db = $admin->save();

        if($db){
            return  user_business_handler()->success('','密码修改成功');
        }
        return  user_business_handler()->fail('密码修改失败');
    }

}
